package com.dc.bobaoge.project.v3.to.v2.business.core;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dc.bobaoge.project.base.core.now.service.TitleService;
import com.dc.bobaoge.project.base.core.old.entity.OldCoreMessageType;
import com.dc.bobaoge.project.base.core.old.mapper.OldCoreMessageTypeMapper;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import com.own.business.sync.trigger.base.method.ResolveMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * TitleResolveMethod
 *
 * @author chenxueli
 * @date 2023-12-22 11:00:00
 */
@Slf4j
@Component
public class TitleResolveMethod implements ResolveMethod {

    @Resource
    private TitleService titleService;

    @Resource
    private OldCoreMessageTypeMapper oldCoreMessageTypeMapper;

    /**
     * 修改的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void update(SyncTrigger trigger) {
        // 查询旧的名称信息
        var id = trigger.getTargetId();
        var title = titleService.getById(id);
        // 设置信息
        var wrapper = new LambdaUpdateWrapper<OldCoreMessageType>()
                .eq(OldCoreMessageType::getMsgTypeId, id)
                .set(OldCoreMessageType::getMsgTypeName, title.getName());
        oldCoreMessageTypeMapper.update(wrapper);
    }

    /**
     * 名称信息
     *
     * @return 名称
     */
    @Override
    public String name() {
        return "title";
    }

}
